﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Text;


namespace mscook.core.domain
{
    public class Magazine : Entity
    {
        public Magazine()
        {
            ResourceBonusSetting = new ResourceBonusSetting(Id, 0, PurchasedCategory.Magazine);
            ReadTimes = 0;
        }
        [Required(ErrorMessage = "标题必填")]
        [StringLength(100, MinimumLength = 1, ErrorMessage = "标题为1-100位")]
        public virtual string Title
        {
            get;
            set;
        }

        [Required(ErrorMessage = "期数必填")]
        [RegularExpression(@"^(?!(0{1,4}(((\\.0{0,2})?))$))([1-9]{1}[0-9]{0,3}|0)(\\.[0-9]{1,2})?$", ErrorMessage = "期数为1-10000期")]
        public virtual string Volume
        {
            get;
            set;
        }

        [Required(ErrorMessage = "年份必填")]
        [RegularExpression(@"^(?!(0{1,4}(((\\.0{0,2})?))$))([1-9]{1}[0-9]{0,3}|0)(\\.[0-9]{1,2})?$", ErrorMessage = "请填写正确的年份格式（例：2013）")]
        public virtual string Year
        {
            get;
            set;
        }

        public virtual int ReadTimes
        {
            set;
            get;
        }

        public virtual ResourceBonusSetting ResourceBonusSetting
        {
            set;
            get;
        }

        /// <summary>
        /// 封面图片
        /// </summary>
        public virtual string ImageName
        {
            get;
            set;
        }

        /// <summary>
        /// not map
        /// </summary>
        public virtual int IntYear
        {
            get
            {
                return Int32.Parse(Year);
            }
        }

        public virtual int IntMonth
        {
            get
            {
                return Int32.Parse(Volume);
            }
        }

        [Required(ErrorMessage = "积分必填")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请填写正确的数字")]
        public virtual int AbsBonus
        {
            set
            {
                ResourceBonusSetting.Bonus = -Math.Abs(value);
            }
            get
            {
                return Math.Abs(ResourceBonusSetting.Bonus);
            }
        }


    }
}
